package com.kenyi.co;

import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.os.Build;

import com.kenyi.co.server.PreLoadX5Service;
import com.kenyi.co.utils.Config;
import com.umeng.commonsdk.UMConfigure;
import com.umeng.socialize.PlatformConfig;

public class MyApplication extends Application {
    private static MyApplication instance;
    private static Context context;
    private String TAG = "com.mutong.aidu";

    public MyApplication() {
    }

    public synchronized static MyApplication getInstance() {
        if (null == instance) {
            instance = new MyApplication();
        }
        return instance;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        context = getApplicationContext();
        UMConfigure.init(this, UMConfigure.DEVICE_TYPE_PHONE, null);
        /**
         * 设置组件化的Log开关
         * 参数: boolean 默认为false，如需查看LOG设置为true
         */

        initX5();
        UMConfigure.setLogEnabled(true);
        PlatformConfig.setWeixin(Config.APP_ID_WX, Config.APP_SECRET_WX);
    }

    private void initX5() {
        Intent intent = new Intent(this, PreLoadX5Service.class);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            startForegroundService(intent);
        } else {
            startService(intent);
        }


        startService(intent);
    }

    public static Context getContext() {
        return context;
    }

}
